require("gq-core");

const tcp = require("gq-core/tcp");
const gqc_mongodb = require("gqc-mongodb");

const socket = global.socket = tcp.createClient({
	// host: '121.40.72.93',
	// family: 'IPv4',
	port: 4001
}, co.wrap(function*() {
	// 插件安装
	gqc_mongodb.install(socket);
	// 声明useing-APP
	const app = yield socket.useApp("Gaubee", "123456", "qaq");

	yield socket.mongodbServer();

	// 将数据库连接对象注册到全局
	global.mongodb = yield socket.mongodbClient(["mongodb://127.0.0.1:27017/shengyi_www"]);
	const cols = [
		"admin",
		"news",
		"tag",
		"section",
		"banner"
	];
	global.tableMap = new Map();
	yield cols.map(co.wrap(function*(col_name) {
		tableMap.set(col_name, yield mongodb.collection(col_name));
	}));

	// 批量注册路由
	socket.multiRegisterRouter(__dirname + "/router");
}, err => {
	console.log(err)
}));